package org.chen.wordwave.act.game;

import android.content.ContentValues;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.OnBackPressedCallback;
import androidx.appcompat.app.AppCompatActivity;

import org.chen.wordwave.R;
import org.chen.wordwave.bean.Configs;
import org.chen.wordwave.tools.AllowPermission;

public class GameOver extends AppCompatActivity {

    private TextView possibleWordTxt, scoreTxt, wordsCountTxt;
    private AllowPermission mmp = new AllowPermission(this);
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.game_over_act);
        super.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
        getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
            @Override
            public void handleOnBackPressed() {
                // 用户按下返回按钮时执行的操作，返回到主页
                Intent intent = new Intent(GameOver.this, Game.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // 清除主页之上的所有 Activity
                startActivity(intent);
            }
        });

        // Init视图
        possibleWordTxt = (TextView)findViewById(R.id.goPossibleWordTxt);
        possibleWordTxt.setTypeface(Configs.juneGull);
        scoreTxt = (TextView)findViewById(R.id.goScoreTxt);
        scoreTxt.setTypeface(Configs.juneGull);
        wordsCountTxt = (TextView)findViewById(R.id.goWordsCountTxt);


        // 显示分数
        scoreTxt.setText(String.valueOf(Configs.score));

        possibleWordTxt.setText(Configs.stringsArray.get(0));

        // 得到你本可以做的其他单词
        if (Configs.stringsArray.size() > 1) {
            wordsCountTxt.setText( String.valueOf(Configs.stringsArray.size()-1) );
        } else {
            wordsCountTxt.setText("0");
        }


        // -再次播放按钮
        Button paButt = (Button)findViewById(R.id.goPlayAgain);
        paButt.setTypeface(Configs.juneGull);
        paButt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }});



        //  - 主页按钮
        Button hButt = (Button)findViewById(R.id.goHomeButt);
        hButt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(GameOver.this, Game.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // 清除主页之上的所有 Activity
                startActivity(intent);
            }});
    }
}
